import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mall/constant/app_dimens.dart';
import 'package:mall/constant/text_style.dart';
import 'package:mall/modules/model/brand_detail_entity.dart';
import 'package:mall/modules/sc/brand_sc.dart';
import 'package:mall/ui/widgets/cached_image.dart';
import 'package:mall/utils/list_placeholder_component/list_placeholder_component.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BrandDetailPage extends StatefulWidget {
  final titleName;
  final id;

  BrandDetailPage(this.titleName, this.id);

  @override
  _BrandDetailPageState createState() => _BrandDetailPageState();
}

class _BrandDetailPageState extends State<BrandDetailPage> {
  // BrandDetailViewModel _brandDetailViewModel = BrandDetailViewModel();
  final sc_brand = Get.put(BrandSc());

  @override
  void initState() {
    super.initState();
    // _brandDetailViewModel.queryBrandDetail(widget.id);
    sc_brand.refreshData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.titleName),
        centerTitle: true,
      ),
      // body: ChangeNotifierProvider(
      //   create: (_) => _brandDetailViewModel,
      //   child:
      //       Consumer<BrandDetailViewModel>(builder: (BuildContext context, BrandDetailViewModel model, Widget child) {
      //     return _initWidget(model);
      //   }),
      // ),
      body: Obx(() => WrappedListPlaceholderComponent.widget1(
            state: sc_brand.loadState.value,
            data: sc_brand.data.value,
            builder: (p0) => _initWidget(p0),
          )),
    );
  }

  Widget _initWidget(BrandDetailEntity? model) {
    if (model == null) {
      return const SizedBox();
    }
    return _contentView(model);
  }

  Widget _contentView(BrandDetailEntity model) {
    return SingleChildScrollView(
        child: Container(
            child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
      Container(
        width: double.infinity,
        child: CachedImageView(double.infinity, ScreenUtil().setHeight(AppDimens.DIMENS_400), model.picUrl),
      ),
      Container(
        margin: EdgeInsets.all(15),
        child: Text(model.desc ?? "", style: FMTextStyle.color_222222_size_13),
      )
    ])));
  }
}
